package sys.person;

import sys.database.Database;
import sys.util.EventUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

abstract public class AbstractPerson {
    String id;
    String name;

    public AbstractPerson(String id, String name) {
        this.id = id;
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    //  OK
    public static void browseEvent() {
        String sql = "select * from event";
        Database database = new Database();
        ResultSet table = database.findTable(sql);
        boolean hasPrint = false;

        try {
            while(table.next()) {
                String eventID = table.getString("eventID");
                String eventName = table.getString("eventName");
                String place = table.getString("place");
                String rule = table.getString("rule");

                if(!hasPrint) {
                    System.out.println("项目编号" + "\t\t" + "项目名称" + "\t\t" + "项目地点" + "\t\t\t" + "项目规则");
                    hasPrint = true;
                }
                System.out.println(eventID + "\t\t" + eventName + "\t\t\t" + place + "\t\t\t" + rule);
            }
        } catch (SQLException e) {
            System.out.println("执行查找操作失败！");
        }
    }

    // OK
    public static void checkScoreOrRankOfEvent(String eventID) {
        String sql = "select * from player where eventID = " + eventID + "order by score desc";
        Database database = new Database();
        ResultSet table = database.findTable(sql);
        boolean hasPrint = false;
        int rank = 1;
        try {
            while(table.next()) {
                String playerID = table.getString("playerID");
                String playerName = table.getString("playerName");
                double playerScore = table.getDouble("score");

                if(!hasPrint) {
                    System.out.println("项目的排名情况：\n");
                    System.out.println("排名" + "    " + "学/工号" + "  " + "姓名" + "    " + "得分" + "    ");
                    hasPrint = true;
                }
                System.out.println("  " + rank + "  " + "  " + playerID + "  " + "  " + playerName + "  " + "  " + playerScore);
                ++rank;
            }
        } catch (SQLException e) {
            System.out.println("执行查找操作失败！");
        }
    }

}
